package com.ciwong.epaper.modules.wordlist.ui;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.View;

import com.ciwong.epaper.R;


/**
 * description：//底部弹窗
 * author：loco
 * email：lzh838330255@163.com
 * date：on 2018/3/26
 */


public class CheckDialogFragment extends BottomSheetDialogFragment implements View
        .OnClickListener {
    private BottomSheetBehavior mBehavior;
    public static final int ALL = 0;//range_all
    public static final int BELOW_80 = 1;//低于80分
    public static final int BELOW_60 = 2;//低于60分
    public static final int OVER_80 = 3;//高于80分
    public static final int OVER_60 = 4;//高于60分

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        View view = View.inflate(getContext(), R.layout.fragment_score_range_dialog, null);
        dialog.setContentView(view);
        mBehavior = BottomSheetBehavior.from((View) view.getParent());
        //是背景色透明
        ((View) view.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent));
        initViewClick(view);

        return dialog;
    }

    private void initViewClick(View view) {
        view.findViewById(R.id.rl_all).setOnClickListener(this);
        view.findViewById(R.id.rl_below80).setOnClickListener(this);
        view.findViewById(R.id.rl_below60).setOnClickListener(this);
        view.findViewById(R.id.rl_over80).setOnClickListener(this);
        view.findViewById(R.id.rl_over60).setOnClickListener(this);
        view.findViewById(R.id.tl_close).setOnClickListener(this);

    }

    @Override
    public void onStart() {
        super.onStart();
        mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);//全屏展开
        mBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.rl_all) {
            mListener.checkScore(ALL);

        } else if (i == R.id.rl_below80) {
            mListener.checkScore(BELOW_80);

        } else if (i == R.id.rl_below60) {
            mListener.checkScore(BELOW_60);

        } else if (i == R.id.rl_over80) {
            mListener.checkScore(OVER_80);

        } else if (i == R.id.rl_over60) {
            mListener.checkScore(OVER_60);

        } else if (i == R.id.tl_close) {
            dismiss();
        }

        mBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
    }

    public ICheckScoreListener mListener;

    public void setCheckScoreListener(ICheckScoreListener listener) {
        mListener = listener;
    }

    public interface ICheckScoreListener {
        void checkScore(int range);
    }
}
